home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 3D / RaveContextSample / Source / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.8 KB  |  186 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        EVENTS            */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <ToolUtils.h>
  11. #include <MacWindows.h>
  12.  
  13. #include "myglobals.h"
  14. #include "myevents.h"
  15. #include "mymenus.h"
  16. #include "misc.h"
  17. #include "qd3d_support.h"
  18. #include "process.h"
  19.  
  20. extern    WindowPtr                gModelWindow;
  21. extern    QD3DSetupOutputType        gModelViewInfo;
  22.  
  23. /****************************/
  24. /*    PROTOTYPES            */
  25. /****************************/
  26.  
  27. static void DoHighLevelEvent(void);
  28. static Boolean IsDAWindow(WindowPtr whichWindow);
  29. static OSErr  hasGotRequiredParams(AppleEvent *appEvent);
  30. static void    HandleMouseDown(void);
  31.  
  32.  
  33. /****************************/
  34. /*    CONSTANTS             */
  35. /****************************/
  36.  
  37.  
  38. /**********************/
  39. /*     VARIABLES      */
  40. /**********************/
  41.  
  42. EventRecord    gTheEvent;
  43.  
  44.  
  45. /******************** HANDLE EVENTS ************************/
  46.  
  47. void HandleEvents(void)
  48. {
  49. char    theChar;
  50. GrafPtr    oldPort;
  51.         
  52.     WaitNextEvent(everyEvent,&gTheEvent, 0, 0);
  53.                 
  54.     switch (gTheEvent.what)
  55.     {
  56.         case    nullEvent:
  57.                 DoModelWindowNullEvent();
  58.                 break;
  59.                 
  60.         case    mouseDown:
  61.                 HandleMouseDown();
  62.                 break;
  63.                 
  64.         case    keyDown:
  65.         case    autoKey:
  66.                 theChar    = gTheEvent.message & charCodeMask;
  67.                 if    ((gTheEvent.modifiers & cmdKey) != 0)
  68.                     HandleMenuChoice(MenuKey(theChar));
  69.                 break;
  70.                 
  71.         case    updateEvt:
  72.                 if (!IsDAWindow((WindowPtr)gTheEvent.message))
  73.                 {
  74.                     GetPort (&oldPort);
  75.                     SetPort ((WindowPtr)gTheEvent.message);
  76.                     BeginUpdate((WindowPtr)gTheEvent.message);
  77.                     DrawControls((WindowPtr)gTheEvent.message);
  78.                     
  79.                     if ((WindowPtr)gTheEvent.message == gModelWindow)
  80.                         DrawModelWindow();
  81.                                             
  82.                     EndUpdate((WindowPtr)gTheEvent.message);
  83.                     SetPort(oldPort); 
  84.                 }
  85.                 else 
  86.                 {
  87.                     BeginUpdate((WindowPtr)gTheEvent.message);
  88.                     EndUpdate((WindowPtr)gTheEvent.message);
  89.                 }
  90.                 break;
  91.                 
  92.         case    kHighLevelEvent:
  93.                 DoHighLevelEvent();
  94.                 break;
  95.     }
  96. }
  97.  
  98.  
  99. /**************** DO HIGH LEVEL EVENT *****************/
  100.  
  101. static void DoHighLevelEvent(void)
  102. {
  103. OSErr    myErr;
  104.  
  105.     myErr = AEProcessAppleEvent(&gTheEvent);
  106. }
  107.  
  108.  
  109. /************** HANDLE MOUSE DOWN *******************/
  110.  
  111. static void HandleMouseDown(void)
  112. {
  113.     WindowPtr        whichWindow;
  114.     short             thePart;
  115.     long            menuChoice, windSize;
  116.     
  117.     thePart    =    FindWindow(gTheEvent.where, &whichWindow);
  118.     switch(thePart)
  119.     {
  120.         case    inMenuBar:
  121.                 menuChoice = MenuSelect(gTheEvent.where);
  122.                 HandleMenuChoice(menuChoice);
  123.                 break;
  124.                 
  125.         case    inSysWindow:
  126.                 SystemClick(&gTheEvent, whichWindow);
  127.                 break;
  128.                 
  129.         case    inDrag:
  130.                 DragWindow(whichWindow,gTheEvent.where, &qd.screenBits.bounds);
  131.                 break;
  132.                 
  133.         case    inGoAway:
  134.                 DisposeWindow (whichWindow);
  135.                 break;
  136.                 
  137.         case    inContent:
  138.                 SelectWindow(whichWindow);
  139.  
  140.                 break;
  141.                 
  142.         case    inGrow:
  143.                 windSize = GrowWindow(whichWindow, gTheEvent.where,
  144.                                     &(**GetGrayRgn()).rgnBBox);
  145.                 if (windSize != 0)
  146.                 {
  147.                     SetPort(whichWindow);
  148.                     EraseRect(&whichWindow->portRect);
  149.                     SizeWindow(whichWindow,LoWord(windSize),
  150.                                 HiWord(windSize), NORMAL_UPDATES);
  151.                     InvalRect(&whichWindow->portRect);
  152.                     
  153.                     if (whichWindow == gModelWindow)            // see if change Skeleton window
  154.                     {
  155.                         QD3D_ChangeDrawSize(&gModelViewInfo);
  156.                     }
  157.                 } 
  158.                 break;
  159.     }
  160. }
  161.  
  162.  
  163. /**************** IS DA WINDOW ***********************/
  164.  
  165. static Boolean IsDAWindow(WindowPtr whichWindow)
  166. {
  167.     if    (whichWindow == nil)
  168.         return (false);
  169.     else
  170.         return (((WindowPeek)whichWindow)->windowKind < 0);
  171. }
  172.  
  173.  
  174.  
  175.  
  176. /*********************** MY APPLE EVENT: QUIT APPLICATION *************************/
  177.  
  178. pascal OSErr MyAE_QuitApplication(AppleEvent *theAppleEvent, AppleEvent *reply,
  179.                             SInt32 handlerRefcon)
  180. {
  181.     #pragma unused(theAppleEvent, reply, handlerRefcon)
  182.  
  183.     CleanQuit();
  184.     return(noErr);
  185. }
  186.